package com.diary.database;

import com.diary.DBUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class RemoveDiary {
    //弃用，并入ChangeDiaryLife中



    //标记删除日记
    //传递两个参数，一个是user，一个是日记id，然后将那篇日记的life状态设为-1，即可认定为被删除

    private static int set_delete(String username,String id) {

        int re = 0;
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;

        String tablename = username;

        try {
            connection = DBUtils.getConnection();

            String sql = "UPDATE `" + username + "` SET life=-1 WHERE id=?;";
            preparedStatement = connection.prepareStatement(sql);

            preparedStatement.setString(1,id);

            re = preparedStatement.executeUpdate();
            // 这里由于是进行新建数据表，不会影响到任何行，所以返回的内容总是false，不能使用这个返回值



        } catch (SQLException e) {
            e.printStackTrace();
        }
        finally {
            DBUtils.close(resultSet,preparedStatement, connection);
        }

        return re;
    }



}
